package com.ns.dcjh.wxapi;

import android.os.Bundle;

import com.alibaba.fastjson.JSONObject;
import com.ns.dcjh.bean.MessageEvent;
import com.ns.dcjh.constant.Constant;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram;
import com.umeng.socialize.weixin.view.WXCallbackActivity;

import org.greenrobot.eventbus.EventBus;

public class WXEntryActivity extends WXCallbackActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onResp(BaseResp resp) {
        if (resp.getType() == ConstantsAPI.COMMAND_LAUNCH_WX_MINIPROGRAM) {
            WXLaunchMiniProgram.Resp mpResp = (WXLaunchMiniProgram.Resp)resp;

            MessageEvent msgEvent = new MessageEvent(Constant.MSG_EVENT_COMMAND_LAUNCH_WX_MINIPROGRAM);
            JSONObject extras = new JSONObject();
            extras.put("extMsg", mpResp.extMsg);
            msgEvent.setExtras(extras);

            EventBus.getDefault().post(msgEvent);
        } else if (resp.getType() == ConstantsAPI.COMMAND_SENDMESSAGE_TO_WX) {
            //微信分享成功
            EventBus.getDefault().post(new MessageEvent(Constant.MSG_EVENT_COMMAND_SENDMESSAGE_TO_WX));
        }

        super.onResp(resp);
    }
}
